package com.chapter05;

import com.bdqn.util.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Test01_Normal {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        // 往数据库中连续插入20000条数据

        long start = System.currentTimeMillis();

        for (int i = 0; i < 20000; i++) {
            Connection connection = JDBCUtils.getConnection();
            String sql = "INSERT INTO goods(`name`) VALUES(?);";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, "张三" + i);

            preparedStatement.executeUpdate();

            preparedStatement.close();
            JDBCUtils.closeResource(connection, preparedStatement, null);
        }
        long end = System.currentTimeMillis();

        System.out.println(end - start); // 249ms 237 250 234
        //

    }
}
